package com.qf.publishsubscribe;

import com.qf.util.ConnectionUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

public class Publisher {

    @Test
    public void publish() throws Exception {
        //1. connection
        Connection connection = ConnectionUtil.getConnection();

        //2. channel
        Channel channel = connection.createChannel();

        //3. 声明exchange
        channel.exchangeDeclare("fanout_exchange", BuiltinExchangeType.FANOUT);

        //4. 声明queue1
        channel.queueDeclare("fanout_queue1",true,false,false,null);

        //5. 声明queue2
        channel.queueDeclare("fanout_queue2",true,false,false,null);

        //6. 绑定exchange和queue1
        channel.queueBind("fanout_queue1","fanout_exchange","没有任何意义对于FANOUT类型交换机");

        //7. 绑定exchange和queue2
        channel.queueBind("fanout_queue2","fanout_exchange","");

        //8. 发送消息到exchange。
        channel.basicPublish("fanout_exchange","没啥用",null,"FANOUT交换机".getBytes());
    }



}
